library(tidyverse)
library(magrittr)
library(lubridate)
library(scales)
library(matrixStats)
library(ggrepel)
library(broom)
library(glue)
library(jsonlite)
library(rvest)
library(RCurl)
library(pander)
library(DT)
library(plotly)
library(cowplot)
library(QuantTools)
library(ggfortify)
library(readxl)
panderOptions("big.mark", ",")
panderOptions("table.split.table", Inf)
panderOptions("table.style", "rmarkdown")
panderOptions("missing", "")
theme_set(theme_bw())
shiftAxisLabel <- function(x, k = 2){
x$x$layout$annotations[[2]]$x <- x$x$layout$annotations[[2]]$x*k
x$x$layout$margin$l <- x$x$layout$margin$l*k
x
}
# Handle updates between 12am & 9am
dt <- Sys.Date()
if (as.numeric(format(Sys.time(), "%H")) <= 9){
dt <- Sys.Date() - 1
}
auStates <- c(
ACT = "Australian Capital Territory",
QLD = "Queensland",
NSW = "New South Wales",
VIC = "Victoria",
SA = "South Australia",
WA = "Western Australia",
NT = "Northern Territory",
TAS = "Tasmania"
)
Disclaimer: This very simple report was prepared by a bioinformatician with no experience in epidemiology or virology, and as such should be treated simply as an alternate viewpoint on the data, which I was simply unable to find elsewhere. Many other people exist with much greater expertise on this subject. However, I do hope this provides a useful perspective which is able to add constructively to the wider discussion. In addition, it should be noted that this is very much focussed on Australian data.
confirmed <- url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv") %>%
read_csv() %>%
pivot_longer(
cols = ends_with("20"),
names_to = "date",
values_to = "confirmed"
) %>%
mutate(
date = str_replace_all(
date, "(.+)/(.+)/(.+)", "20\\3-\\1-\\2"
) %>%
ymd()
) %>%
dplyr::rename(
Country = `Country/Region`
) %>%
dplyr::mutate(
Country = case_when(
`Province/State` == "Hubei" ~ "China (Hubei)",
`Province/State` == "Hong Kong" ~ "Hong Kong",
grepl("China", Country) & !`Province/State` %in% c("Hubei", "Hong Kong") ~ "China (Other)",
Country == "Korea, South" ~ "South Korea",
Country == "Congo (Kinshasa)" ~ "DR Congo",
Country == "Congo (Brazzaville)" ~ "Congo",
!grepl("China", Country) ~ Country
)
) %>%
dplyr::filter(
!is.na(confirmed)
) %>%
dplyr::select(-Lat, -Long)
guardData <- fromJSON("https://interactive.guim.co.uk/docsdata/1q5gdePANXci8enuiS4oHUJxcxC13d6bjMRSicakychE.json")
altAU <- guardData$sheets$updates %>%
as_tibble() %>%
mutate(
`Province/State` = auStates[State],
Country = "Australia",
Date = parse_date_time(Date, orders = "%d/%m/%Y") %>% ymd()
) %>%
dplyr::select(`Province/State`, Country, date = Date, confirmed = `Cumulative case count`) %>%
mutate(confirmed = as.numeric(confirmed)) %>%
arrange(`Province/State`, date) %>%
tidyr::complete(`Province/State`, Country, date) %>%
group_by(`Province/State`) %>%
fill(confirmed) %>%
dplyr::filter(!is.na(confirmed)) %>%
ungroup()
# Add the data, with the Guardian API being preferentialy selected
confirmed %<>%
mutate(source = "JHU") %>%
bind_rows(
mutate(altAU, source = "API")
) %>%
arrange(
date, `Province/State`, source
) %>%
distinct(`Province/State`, Country, date, .keep_all = TRUE) %>%
dplyr::select(-source)
latestAU <- list()
nswRecov <- nswTests <- NA_real_
nswUrl <- "https://www.health.nsw.gov.au/_layouts/feed.aspx?xsl=1&web=/news&page=4ac47e14-04a9-4016-b501-65a23280e841&wp=baabf81e-a904-44f1-8d59-5f6d56519965&pageurl=/news/Pages/rss-nsw-health.aspx" %>%
read_xml() %>%
xml_find_all("//item") %>%
.[[1]] %>%
as.character() %>%
str_split("\n") %>%
.[[1]] %>%
str_subset("https") %>%
str_extract("https[^<]+")
nswTable <- nswUrl %>%
read_html() %>%
html_nodes("body") %>%
xml_find_all("//table") %>%
.[[1]] %>%
html_table() %>%
set_colnames(
str_replace_all(colnames(.), "\\u200b", "")
) %>%
mutate_all(str_replace_all, pattern = "\\u200b", replacement = "") %>%
mutate(
Count = str_remove_all(Count, "[\\*,]") %>% as.numeric,
Cases = str_replace_all(Cases, " +", " ")
)
nswTests <- nswTable %>%
dplyr::filter(
str_detect(Cases, "Total tests carried out")
) %>%
.[["Count"]]
nswRecov <- nswTable %>%
dplyr::filter(str_detect(Cases, "recovered")) %>%
.[["Count"]]
latestAU$NSW <- tibble(
State = "New South Wales",
date = dt,
confirmed = nswTable %>%
dplyr::filter(str_detect(Cases, "Confirmed cases")) %>%
.[["Count"]],
deaths = nswTable %>%
dplyr::filter(str_detect(Cases, "Deaths")) %>%
.[["Count"]],
recovered = nswRecov,
tested = nswTests
)
qldRecov <- qldTests <- NA_real_
qldUrl <- "https://www.qld.gov.au/health/conditions/health-alerts/coronavirus-covid-19/current-status/statistics"
qldTests <- qldUrl %>%
read_html() %>%
html_nodes("body") %>%
xml_find_all("//div[contains(@class, 'tested')]") %>%
html_text() %>%
str_extract("[0-9,]+") %>%
str_remove_all(",") %>%
as.numeric()
qldTable <- qldUrl %>%
read_html() %>%
html_nodes("body") %>%
xml_find_all("//table[@id = 'QLD_Cases']") %>%
html_table() %>%
.[[1]]
qldConfirmed <- qldTable %>%
dplyr::filter(str_detect(Cases, "Number of cases")) %>%
pull(Total) %>%
str_remove_all(",") %>%
as.numeric()
qldActive <- qldTable %>%
dplyr::filter(str_detect(Cases, "Active")) %>%
pull(Total) %>%
as.numeric()
qldDeaths <- qldTable %>%
dplyr::filter(str_detect(Cases, "Deaths")) %>%
pull(Total) %>%
as.numeric()
# qldRecov <- qldTable %>%
# dplyr::filter(Cases == "Recovered") %>%
# .[["Total"]] %>%
# str_remove_all(",") %>%
# as.numeric()
qldRecov <- qldConfirmed - qldActive - qldDeaths
latestAU$QLD <- tibble(
State = "Queensland",
date = dt,
confirmed = qldConfirmed,
deaths = qldDeaths,
recovered = qldRecov,
tested = qldTests
)
vicRecov <- vicTests <- NA_real_
vicUrl <- c(
"https://www.dhhs.vic.gov.au/coronavirus-update-victoria-{format(dt, '%d')}-{format.Date(dt, '%B')}-{year(dt)}",
"https://www.dhhs.vic.gov.au/coronavirus-update-victoria-{day(dt)}-{format.Date(dt, '%B')}-{year(dt)}",
"https://www.dhhs.vic.gov.au/coronavirus-update-victoria-{format(dt - 1, '%d')}-{format.Date(dt - 1, '%B')}-{year(dt-1)}",
"https://www.dhhs.vic.gov.au/coronavirus-update-victoria-{day(dt - 1)}-{format.Date(dt - 1, '%B')}-{year(dt-1)}"
) %>%
vapply(glue, character(1)) %>%
str_to_lower() %>%
vapply(url.exists, logical(1)) %>%
which() %>%
names() %>%
.[[1]]
vicTxt <- vicUrl %>%
read_html() %>%
html_nodes("body") %>%
html_text() %>%
str_split("\n") %>%
.[[1]] %>%
str_trim() %>%
.[. != ""] %>%
str_subset("(test|recovered|total|died)") %>%
stringi::stri_trans_general("latin-ascii")
vicTests <- vicTxt %>%
str_subset(".*[0-9]+.*tests") %>%
.[[1]] %>%
str_replace_all(
".* ([0-9,]+)[^0-9]test(ed|s|ing).+",
"\\1"
) %>%
str_remove_all(",") %>%
as.numeric()
vicRecov <- vicTxt %>%
str_subset("[0-9]+.+recovered") %>%
str_trim() %>%
str_replace_all(".*[^0-9,]([0-9,]+)[^0-9]*people have recovered.*", "\\1") %>%
str_remove(",") %>%
as.numeric()
latestAU$VIC <- tibble(
State = "Victoria",
date = dt,
confirmed = vicTxt %>%
str_subset("(coronavirus|total).+cases") %>%
str_subset("Victoria") %>%
# str_subset("regional", negate = TRUE) %>%
# str_replace_all(".+[^0-9,]+ ([0-9,]+) cases[^0-9,].+", "\\1") %>%
str_replace_all(".+total ([0-9,]+) cases.+", "\\1") %>%
str_remove_all(",") %>%
as.numeric() %>%
.[!is.na(.)] %>%
unique(),
deaths = vicTxt %>%
str_subset("died") %>%
str_replace_all(".+[^0-9]([0-9,]+)[^0-9]*people have died.+", "\\1") %>%
str_remove_all(",") %>%
as.numeric() %>%
unique(),
recovered = vicRecov,
tested = vicTests
)
waTests <- waRecov <- NA_real_
waMedia <- "https://ww2.health.wa.gov.au/News/Media-releases-listing-page" %>%
read_html() %>%
html_nodes("body") %>%
xml_find_all("//a[contains(@title, '19 update')]") %>%
html_attr("href") %>%
str_subset("2020$") %>%
.[[1]]
waUrl <- glue("https://ww2.health.wa.gov.au{waMedia}")
waTxt <- waUrl %>%
read_html() %>%
html_nodes("body") %>%
html_text() %>%
str_split("\n") %>%
.[[1]] %>%
str_trim() %>%
.[. != ""] %>%
stringi::stri_trans_general("latin-ascii")
waTests <- waTxt %>%
str_subset("test(s|ed).*performed") %>%
str_replace_all(".+ ([0-9,]+) COVID.+", "\\1") %>%
str_remove_all(",") %>%
as.numeric()
waRecov <- waTxt %>%
str_subset("recovered") %>%
str_subset("[0-9]..") %>%
str_remove_all("COVID-19") %>%
str_replace_all("[^0-9]*([0-9]*)[^0-9]*", "\\1") %>%
as.numeric()
latestAU$WA <- tibble(
State = "Western Australia",
date = dt,
confirmed = waTxt %>%
str_subset("(State|Western)") %>%
str_subset("total") %>%
str_subset("recovered", TRUE) %>%
str_remove_all("COVID.*19") %>%
str_replace_all("[^0-9]+([0-9]+)[^0-9]+", "\\1") %>%
as.numeric() %>%
.[!is.na(.)] %>%
unique(),
deaths = 9, # Needs to be done manually again
recovered = waRecov,
tested = waTests
)
saRecov <- saTests <- NA_real_
saUrl <- "https://www.covid-19.sa.gov.au/home/dashboard"
saTxt <- saUrl %>%
read_html() %>%
xml_find_all("//div[contains(@class, 'accordion__content')]") %>%
.[[1]] %>%
html_text() %>%
str_split("\r\n") %>%
.[[1]] %>%
str_trim() %>%
.[. != ""]
## The dashboard is unreliable so use SA Health press releases as an additional source
## These don't appear until late afternoon, so this is a pain in the arse quite frankly
altSaUrl <- c(
"https://www.sahealth.sa.gov.au/wps/wcm/connect/public+content/sa+health+internet/about+us/news+and+media/all+media+releases/covid-19+update+{day(dt)}+{format(dt, '%B')}",
"https://www.sahealth.sa.gov.au/wps/wcm/connect/public+content/sa+health+internet/about+us/news+and+media/all+media+releases/covid-19+update+{day(dt - 1)}+{format(dt - 1, '%B')}",
"https://www.sahealth.sa.gov.au/wps/wcm/connect/public+content/sa+health+internet/about+us/news+and+media/all+media+releases/covid-19+update+{day(dt)}+{format(dt, '%B')}+2020",
"https://www.sahealth.sa.gov.au/wps/wcm/connect/public+content/sa+health+internet/about+us/news+and+media/all+media+releases/covid-19+update+{day(dt - 1)}+{format(dt - 1, '%B')}+2020"
) %>%
vapply(glue, character(1)) %>%
str_to_lower()
validSa <- altSaUrl %>%
vapply(url.exists, logical(1)) %>%
which() %>%
names() %>%
sapply(read_html, simplify = FALSE) %>%
lapply(html_node, css = "body") %>%
vapply(function(x){!is.na(x)}, logical(1)) %>%
which() %>%
names() %>%
.[[1]]
altSaTxt <- validSa %>%
read_html() %>%
html_node("body") %>%
xml_find_all("//section[@class = 'main-content']") %>%
html_text() %>%
str_split("\n") %>%
.[[1]] %>%
str_trim() %>%
.[. != ""]
saTests <- c(
saTxt %>%
str_replace_all(".+[^0-9,]([0-9,]+)[^0-9,]+tests.+", "\\1") %>%
str_remove_all("[, ]") %>%
as.numeric(),
altSaTxt %>%
str_subset("tests") %>%
str_replace_all(".+ ([0-9,]+) test.+", "\\1") %>%
str_remove_all(",") %>%
as.numeric()
) %>%
max(na.rm = TRUE)
saTable <- "https://www.covid-19.sa.gov.au/" %>%
read_html() %>%
html_node("body") %>%
xml_find_all("//div[@class = 'focus-boxes']") %>%
html_text() %>%
str_split("\r\n") %>%
.[[1]] %>%
str_trim() %>%
.[.!=""] %>%
.[seq(length(.), 1, by = -1)] %>%
.[!str_detect(., "(Data current|View the|See more)")] %>%
matrix(ncol = 2, byrow = TRUE) %>%
set_colnames(c("Cases", "Total")) %>%
as.data.frame(stringsAsFactors = FALSE) %>%
mutate(
Total = as.numeric(Total),
Cases = str_remove_all(Cases, "in South Australia")
)
saRecov <- c(
saTable %>%
dplyr::filter(str_detect(Cases, "recovered")) %>%
.[["Total"]],
altSaTxt %>%
str_subset("(cleared|recovered)") %>%
str_replace_all(".+ ([0-9]+) people have.+", "\\1") %>%
as.numeric()
) %>%
max(na.rm = TRUE)
latestAU$SA <- tibble(
State = "South Australia",
date = dt,
confirmed = saTable %>%
dplyr::filter(str_detect(Cases, "Total cases")) %>%
.[["Total"]],
deaths = 4, # Only able to be added manually. Thanks SA Health
recovered = saRecov,
tested = saTests
)
actRecov <- actTests <- NA_real_
actUrl <- "https://www.covid19.act.gov.au/home"
actTable <- actUrl %>%
read_html() %>%
html_nodes("body") %>%
xml_find_all(
"//div[contains(@class, 'spf-article-card--tabular')]"
) %>%
html_text() %>%
str_split("\r\n") %>%
.[[4]] %>%
str_trim() %>%
setdiff(y = "") %>%
str_remove_all("[,*]") %>%
matrix(ncol = 2, byrow = TRUE) %>%
set_colnames(c("Cases", "Total")) %>%
as.data.frame(stringsAsFactors = FALSE) %>%
mutate(Total = as.numeric(Total))
actTests <- actTable %>%
dplyr::filter(!str_detect(Cases, "recovered")) %>%
.[["Total"]] %>%
sum()
actRecov <- actTable %>%
dplyr::filter(str_detect(Cases, "recov")) %>%
.[["Total"]]
latestAU$ACT <- tibble(
State = "Australian Capital Territory",
date = dt,
confirmed = actTable %>%
dplyr::filter(str_detect(Cases, "Confirmed cases")) %>%
.[["Total"]],
deaths = 3, # Only able to be added manually.
recovered = actRecov,
tested = actTests
)
tasUrl <- "https://www.coronavirus.tas.gov.au/facts/cases-and-testing-updates"
tasTables <- tasUrl %>%
read_html() %>%
html_nodes("body") %>%
xml_find_all("//table") %>%
html_table() %>%
.[1:2] %>%
lapply(mutate, Number = str_remove_all(Number, "[^0-9]")) %>%
lapply(mutate, Number = as.numeric(Number))
latestAU$TAS <- tibble(
State = "Tasmania",
date = dt,
confirmed = dplyr::filter(
tasTables[[2]],
str_detect(`Cases in Tasmania`, "Total cases")
)$Number,
deaths = dplyr::filter(
tasTables[[2]],
str_detect(`Cases in Tasmania`, "Deaths")
)$Number,
recovered = dplyr::filter(
tasTables[[2]],
`Cases in Tasmania` == "Recovered"
)$Number,
tested = dplyr::filter(
tasTables[[1]],
`Laboratory tests` == "Total laboratory tests"
)$Number
)
# ntRecov <- ntTests <- NA_real_
# ntUrl <- "https://coronavirus.nt.gov.au/"
# ntTxt <- ntUrl %>%
# read_html() %>%
# html_nodes("body") %>%
# xml_find_all(
# "//div[contains(@class, 'header-widget')]"
# ) %>%
# html_text() %>%
# str_split("\r\n") %>%
# .[[1]] %>%
# str_trim() %>%
# .[. != ""]
# ntTests <- ntTxt %>%
# str_subset("test") %>%
# str_extract("([0-9,]+)") %>%
# str_remove_all(",") %>%
# as.numeric()
# ntRecov <- ntTxt %>%
# str_subset("recovered") %>%
# str_extract("[0-9,]+") %>%
# str_remove_all(",") %>%
# as.numeric()
ntUrl <- "https://coronavirus.nt.gov.au/current-status"
ntTable <- ntUrl %>%
read_html() %>%
html_nodes("body") %>%
xml_find_all("//div[contains(@class, 'covid-card-stats')]") %>%
html_text() %>%
str_split("\r\n") %>%
.[[1]] %>%
str_trim() %>%
.[. != ""] %>%
matrix(ncol = 2, byrow = TRUE) %>%
set_colnames(c("Total", "Category")) %>%
as.data.frame() %>%
mutate(Total = str_remove_all(Total, ",") %>% as.numeric())
latestAU$NT <- tibble(
State = "Northern Territory",
date = dt,
confirmed = dplyr::filter(ntTable, str_detect(Category, "confirmed"))$Total,
deaths = 0,
recovered = dplyr::filter(ntTable, str_detect(Category, "recovered"))$Total,
tested = dplyr::filter(ntTable, str_detect(Category, "tests"))$Total
)
latestAU %<>%
bind_rows() %>%
mutate(Country = "Australia")
latestAU %>%
dplyr::select(
`Province/State` = State, Country, date, recovered
) %>%
write_tsv(
here::here(glue("recovered/recovered_{dt}.tsv"))
)
confirmed %<>%
bind_rows(
dplyr::select(latestAU, any_of(colnames(.)), `Province/State` = State)
) %>%
arrange(date) %>%
mutate(f = paste(`Province/State`, Country, sep = "_")) %>%
split(f = .$f) %>%
lapply(mutate, confirmed = cummax(confirmed)) %>%
bind_rows() %>%
dplyr::select(-f) %>%
arrange(Country, `Province/State`, date, desc(confirmed)) %>%
dplyr::distinct(`Province/State`, Country, date, .keep_all = TRUE)
# This is 24hrs behind but has the censored values
# We can update the recovered time series from here
# These deaths are more accurate than JHU and the JHU TS should be updated
nswJSON <- "https://nswdac-covid-19-postcode-heatmap.azurewebsites.net/datafiles/data_Cases2.json" %>%
fromJSON() %>%
.[["data"]] %>%
as_tibble() %>%
separate(Date, into = c("Day", "Month")) %>%
mutate(
Date = paste0("2020-", Month, "-", Day) %>%
as_datetime(format = "%Y-%b-%d") %>%
ymd()
) %>%
group_by(Date) %>%
summarise(
confirmed = sum(Cases),
recovered = sum(Recovered + censored),
deaths = sum(Deaths)
) %>%
mutate(
`Province/State` = "New South Wales",
Country = "Australia"
) %>%
dplyr::rename(date = Date)
auRecTS <- list.files(here::here("recovered"), pattern = "rec.*tsv",full.names = TRUE) %>%
lapply(read_tsv) %>%
bind_rows() %>%
dplyr::filter(!(date %in% nswJSON$date & `Province/State` == "New South Wales")) %>%
bind_rows(dplyr::select(nswJSON, any_of(colnames(.)))) %>%
arrange(`Province/State`, date) %>%
group_by(`Province/State`) %>%
mutate(recovered = cummax(recovered))
recovered <- url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv") %>%
read_csv() %>%
pivot_longer(
cols = ends_with("20"),
names_to = "date",
values_to = "recovered"
) %>%
mutate(
date = str_replace_all(
date, "(.+)/(.+)/(.+)", "20\\3-\\1-\\2"
) %>%
ymd()
) %>%
dplyr::rename(
Country = `Country/Region`
) %>%
dplyr::mutate(
Country = case_when(
`Province/State` == "Hubei" ~ "China (Hubei)",
`Province/State` == "Hong Kong" ~ "Hong Kong",
grepl("China", Country) & !`Province/State` %in% c("Hubei", "Hong Kong") ~ "China (Other)",
grepl("Korea, South", Country) ~ "South Korea",
Country == "Congo (Kinshasa)" ~ "DR Congo",
Country == "Congo (Brazzaville)" ~ "Congo",
!grepl("China", Country) ~ Country
)
) %>%
dplyr::select(-Lat, -Long) %>%
bind_rows(auRecTS) %>%
group_by(
`Province/State`, Country, date
) %>%
summarise_at(vars(recovered), max)
deaths <- url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv") %>%
read_csv() %>%
pivot_longer(
cols = ends_with("20"),
names_to = "date",
values_to = "deaths"
) %>%
mutate(
date = str_replace_all(
date, "(.+)/(.+)/(.+)", "20\\3-\\1-\\2"
) %>%
ymd()
) %>%
dplyr::rename(
Country = `Country/Region`
) %>%
dplyr::mutate(
Country = case_when(
`Province/State` == "Hubei" ~ "China (Hubei)",
`Province/State` == "Hong Kong" ~ "Hong Kong",
grepl("China", Country) & !`Province/State` %in% c("Hubei", "Hong Kong") ~ "China (Other)",
Country == "Korea, South" ~ "South Korea",
Country == "Congo (Kinshasa)" ~ "DR Congo",
Country == "Congo (Brazzaville)" ~ "Congo",
!grepl("China", Country) ~ Country
)
) %>%
dplyr::select(-Lat, -Long) %>%
bind_rows(
dplyr::select(latestAU, any_of(colnames(.)), `Province/State` = State)
) %>%
bind_rows(
dplyr::select(nswJSON, any_of(colnames(.)))
) %>%
arrange(date) %>%
mutate(f = paste(`Province/State`, Country, sep = "_")) %>%
split(f = .$f) %>%
lapply(mutate, deaths = cummax(deaths)) %>%
bind_rows() %>%
dplyr::select(-f) %>%
dplyr::distinct(`Province/State`, Country, date, .keep_all = TRUE)
predRecovered <- confirmed %>%
rename(
recovered = confirmed
) %>%
mutate(
date = date + 21
) %>%
left_join(deaths) %>%
mutate(recovered = recovered - deaths) %>%
dplyr::select(
`Province/State`, Country, date,recovered
)
# predRecovered %>%
# rename(pred = recovered) %>%
# left_join(recovered) %>%
# group_by(Country, date) %>%
# summarise_at(
# vars(pred, recovered), sum
# ) %>%
# ungroup() %>%
# dplyr::filter(Country != "Sweden") %>%
# ggplot(aes(pred, recovered)) +
# geom_point() +
# geom_abline(slope = 1) +
# geom_smooth(method = "lm") +
# scale_x_log10(labels = comma) +
# scale_y_log10(labels = comma)
wikiPops <- read_tsv("wikiPops.tsv") %>%
mutate_at(c("Region", "Continent"), as.factor)
alwaysShow <- c("Australia", "New Zealand", "US", "Canada", "United Kingdom", "Taiwan*", "Singapore", "South Korea", "China (Other)", "China (Hubei)", "Hong Kong", "Japan", "Ireland", "Russia", "Brazil", "Kuwait", "Finland", "Norway")
countryCols <- confirmed %>%
dplyr::filter(confirmed > 0) %>%
arrange(date) %>%
distinct(Country) %>%
left_join(wikiPops) %>%
mutate(
Region = str_replace_all(
Region, "(Southern|Western) Europe", "Southern & Western Europe"
),
Region = str_replace_all(
Region, "(Central|Southern) Asia", "Central & Southern Asia"
),
Region = str_replace_all(
Region, "(Central America|Northern America|Caribbean)", "Caribbean, Central & Northern America"
),
Region = str_replace_all(
Region, "(Eastern|Middle|Southern) Africa", "Eastern, Middle & Southern Africa"
)
) %>%
droplevels() %>%
split(f = .$Region) %>%
lapply(
function(x){
mutate(x, rgb = hue_pal()(nrow(x)))
}
) %>%
bind_rows() %>%
with(structure(rgb, names = Country))
Data for confirmed cases, recoveries and fatalities was primarily sourced from Johns Hopkins University, using the datasets provided at https://github.com/CSSEGISandData/COVID-19. JHU data is now updated every 24 hours at approximately 3:30(UTC), which is about 1:00PM in Adelaide. As such no accurate, daily updates for international data can be produced until after that time. Importantly, dates associated with confirmed cases from this data source, may differ from dates associated with confirmed cases from Australian sources. For example, cases reported in the morning in Australia may be assigned to the previous day in US data sources.
Live hourly updates for Australia are available from https://covid-19-au.github.io/ for those who would like an up to the minute breakdown of confirmed cases. Numbers used for generation of this page are updated periodically throughout the day using values provided by individual states at NSW, QLD, VIC, WA, SA, TAS, ACT and the NT. Additional Australian data was obtained from The Guardian. Whilst dates from the Guardian are likely to be reported using the UK as a reference, this is still closer to Australian time zones than USA-based data.
Population sizes were obtained from 2019 UN Estimates. Given the disparity of infection within China, China was broken into Hubei Province and the rest of China, with Hong Kong and Taiwan already being considered as separate countries in all datasets. Population estimates for Hubei Province were taken from the 2018 estimates given by Statista.com and this is likely to be a very slight underestimate.
Confirmed cases of COVID-19 as provided by the Chinese Government have been discussed elsewhere as unusual, and data appears potentially unreliable. In this analysis, discussions regarding accurate Chinese reporting are not considered further and data is simply presented as supplied by JHU.
However, all countries are likely to contain many unreported cases given the incomplete testing regimes in place for most countries. Similarly, reporting in many countries may have features that cause concerns regarding data integrity and this makes comparison across countries difficult. Information on recovered cases has been difficult to accurately obtain due inconsistent methods for considering a case as recovered, and lack of reporting for these cases in many jurisdictions. In Australia, some states (e.g. NSW & QLD) have only begun releasing these figures in mid-April, whilst other states such as Victoria were releasing these numbers from mid-March.
startingPoint <- 4
minPop <- 2e6
For this section, most data is presented relative to population size. Growth in infection rates is only shown after the point at which the cumulative confirmed infection rate breached 4 confirmed cases / million. This equates to about 101 confirmed cases within Australia, and is broadly comparable to the “Days since passing 100 confirmed cases” commonly shown elsewhere.
Most plots in this section have been filtered for countries with a population, cases or fatalities larger than a given value. Due to their significantly strong or poor performances, a handful of countries have been specified to be always included regardless of this filter. These countries are Australia, Brazil, Canada, China (Hubei), China (Other), Finland, Hong Kong, Ireland, Japan, Kuwait, New Zealand, Norway, Russia, Singapore, South Korea, Taiwan, US and United Kingdom
Before exploring individual countries, a regional perspective may be helpful. Importantly, only Oceania, Eastern Asia, Western Europe and Southern Europe have successfully controlled the infection rate. Most other regions are still experiencing exponential growth.
ggplotly(
confirmed %>%
inner_join(wikiPops) %>%
mutate(
Continent = str_replace_all(Continent, "(Oceania|Asia)", "Asia & Oceania")
) %>%
group_by(Continent, Region, Country, Population, date) %>%
summarise(confirmed = sum(confirmed)) %>%
ungroup() %>%
group_by(Continent, Region, date) %>%
summarise(rate = round(1e6*sum(confirmed)/sum(Population), 2)) %>%
dplyr::filter(
date < dt,
date > "2020-02-18",
rate > startingPoint
# Region != "Eastern Asia"
) %>%
ggplot(aes(date, rate, colour = Region)) +
geom_line() +
scale_y_log10(label = comma_format(1)) +
facet_wrap(~Continent, ncol = 2) +
labs(x = "Date", y = "Cumulative Infection Rate (Confirmed Cases / Million)")
) %>%
shiftAxisLabel(k = 1.5)
Current regional cumulative infection rates. Lines are shown from the point that regional cases exceeded 4 confirmed cases / million. Rates are calculated within each region using regional populations.
ggplotly(
confirmed %>%
inner_join(wikiPops) %>%
mutate(
Continent = str_replace_all(Continent, "(Oceania|Asia)", "Asia & Oceania")
) %>%
group_by(Continent, Region, Country, Population, date) %>%
summarise(confirmed = sum(confirmed)) %>%
ungroup() %>%
group_by(Continent, date) %>%
mutate(Population = sum(Population)) %>%
ungroup() %>%
group_by(Continent, Region, date) %>%
summarise(
confirmed = sum(confirmed),
Population = unique(Population)
) %>%
mutate(
daily = c(0, diff(confirmed))
) %>%
ungroup() %>%
dplyr::filter(
daily > 0 | confirmed > 0,
date < dt
) %>%
mutate(
`Daily Rate` = round(1e6 * daily / Population, 2)
) %>%
rename(Date = date) %>%
ggplot(
aes(Date, `Daily Rate`, fill = Region)
) +
geom_bar(stat = "identity") +
geom_line(
aes(Date, MA),
data = . %>%
group_by(Continent, Date) %>%
summarise(
`Daily Rate` = sum(`Daily Rate`)
) %>%
mutate(MA = sma(`Daily Rate`, 7)),
inherit.aes = FALSE
) +
scale_colour_manual(values = c(NA, "black")) +
scale_x_date(expand = expansion(c(0, 0.03))) +
scale_y_continuous(expand = expansion(c(0, 0.05))) +
facet_wrap(~Continent, ncol = 2, scales = "free") +
labs(
x = "Date",
y = "Daily New Infection Rate (cases / million)"
),
tooltip = c("Date", "Daily Rate", "Region")
) %>%
shiftAxisLabel(k = 3)
Daily new confirmed infections, shown as cases / million. Values are calculated within the total population for each continent. The solid black line is the 7-day simple moving average calculated within each continent
Confirmed cases in this table are effectively the cumulative, confirmed incidence rate. Recovered patients and those who have passed away are still included in these numbers.
confirmed %>%
group_by(Country, date) %>%
summarise(confirmed = sum(confirmed)) %>%
ungroup() %>%
group_by(Country) %>%
dplyr::filter(
date == max(date),
) %>%
ungroup() %>%
inner_join(wikiPops) %>%
mutate(
rate = 1e6*confirmed / Population,
occurrence = Population / confirmed,
Population = round(Population, -3) / 1e6
) %>%
dplyr::filter(rate >= 1) %>%
arrange(desc(rate)) %>%
rename_at(vars(everything()), str_to_title) %>%
dplyr::select(
Continent, Region, Country,
Date, Confirmed,
`Population (millions)` = Population,
`Rate (Cases per Million)` = Rate,
Occurrence
) %>%
datatable(
options = list(
pageLength = 25,
autoWidth = TRUE,
searchCols = list(
NULL, NULL, NULL, NULL, NULL,
list(
search = glue(
'{minPop/1e6 + 0.001} ... {max(wikiPops$Population/1e6)}'
)
),
NULL
)
),
filter = 'top',
class = "stripe",
rownames = FALSE,
caption = paste(
"The most impacted countries studied here and shown as a proportion of total population.",
"The initial filter is set so that only countries with a population greater than", comma(minPop), "are shown.",
"All fields are searchable and sortable.",
"To filter numeric columns, either use the slider or enter the values in the form 'min ... max'.",
"To filter text columns, partial matching used in a case-insensitive manner.",
"Populations have been rounded to the nearest thousand to make reading values easier.",
"'Rate' represents the latest confirmed infection rate as cumulative cases per million people, whilst 'Occurrence' represents the number of people expected before one case is found, assuming an even distribution amongst the population.",
"In other words, one in every 'Occurrence' people within the population have been confirmed to have contracted COVID-19.",
"Occurrence is inversely proportional to Rate.",
"No adjustment has been made in this table for patients who have recovered or passed away.",
"Whilst the virus spreads with no regard to population size, the rate as shown here indicates the degree of stress which each country's health-care system is likely to be experiencing.",
"Several countries shown here have not attracted much media attention due lower case numbers than China and Italy, but are likely to be experiencing significant duress.",
"Continent and Region information is as provided by the UN classifications."
)
) %>%
formatCurrency(
columns = c("Population (millions)"),
currency = "",
digits = 3,
mark = ","
) %>%
formatCurrency(
columns = c("Confirmed", "Rate (Cases per Million)", "Occurrence"),
currency = "",
digits = 0,
mark = ","
)
ausDays <- confirmed %>%
dplyr::filter(Country == "Australia") %>%
group_by(Country, date) %>%
summarise_at(vars(confirmed), sum) %>%
left_join(wikiPops) %>%
mutate(rate = 1e6 * confirmed / Population) %>%
dplyr::filter(rate > startingPoint) %>%
nrow()
minDays <- ausDays - 30
# Use Singapore as that has the longest dataset besides Hubei
nDays <- confirmed %>%
dplyr::filter(Country == "Singapore") %>%
group_by(Country, date) %>%
summarise(confirmed = sum(confirmed)) %>%
ungroup() %>%
left_join(wikiPops) %>%
mutate(
rate = 1e6*confirmed / Population
) %>%
dplyr::filter(rate > startingPoint) %>%
nrow() %>%
subtract(1)
refRate <- c(2, 4, 8)
minPop <- 8e6
p <- confirmed %>%
group_by(Country, date) %>%
summarise(confirmed = sum(confirmed)) %>%
ungroup() %>%
inner_join(
dplyr::filter(
wikiPops, Population > minPop | Country %in% alwaysShow
)
) %>%
mutate(
rate = 1e6*confirmed / Population
) %>%
dplyr::filter(
rate > startingPoint
) %>%
group_by(Country) %>%
mutate(
days = date - min(date)
) %>%
dplyr::filter(
max(days) >= minDays | Country %in% alwaysShow
) %>%
ungroup() %>%
mutate(
days = as.integer(days),
rate = round(rate, 2)
) %>%
dplyr::filter(days <= nDays | Country %in% alwaysShow) %>%
arrange(date) %>%
mutate(
Region = str_replace_all(
Region, "(Southern|Western) Europe", "Southern & Western Europe"
),
Region = str_replace_all(
Region, "(Central|Southern) Asia", "Central & Southern Asia"
),
Region = str_replace_all(
Region, "(Central America|Northern America|Caribbean)", "Caribbean, Central & Northern America"
),
Region = str_replace_all(
Region, "(Eastern|Middle|Southern) Africa", "Eastern, Middle & Southern Africa"
),
Country = fct_inorder(Country),
Region = fct_lump(Region, n = 11)
) %>%
rename_all(str_to_title) %>%
mutate(ymax = max(Rate)) %>%
ggplot(
aes(Days, Rate, colour = Country, Date = Date, Confirmed = Confirmed)
) +
geom_segment(
aes(x, y, xend = xmax, yend = ymax),
data = . %>%
dplyr::slice(seq_along(refRate)) %>%
dplyr::select(ymax) %>%
mutate(
ymax = ymax*1.2,
x = 0,
y = startingPoint,
xmax = refRate*log2(ymax / startingPoint)
),
inherit.aes = FALSE,
colour = "grey80",
linetype = 2
) +
geom_line() +
scale_x_continuous(
expand = expansion(mult = c(0, 0.05)),
) +
scale_y_log10(
expand = expansion(mult = c(0, 0.05)),
label = comma
) +
scale_colour_manual(values = countryCols) +
xlab(
paste(
"Days since passing",
startingPoint,
"confirmed cases/million"
)
) +
ylab("Confirmed Cumulative Infection Rate (cases/million)") +
facet_wrap(~Region, ncol = 3)
ggplotly(
p,
tooltip = c(
"Days", "Rate", "Country", "Date", "Confirmed"
)) %>%
shiftAxisLabel(k = 1.5)
COVID-19 Confirmed Cumulative Infection Rate for countries which have exceeded 4 confirmed cases/million for 85 or more days, and with populations greater than 8,000,000, apart from a small number of specifically included countries. Data is only shown for the first 148 calendar days since passing 4 confirmed cases/million. Note that from the day records begin in this dataset (2020-01-22), the confirmed infection rate in Hubei was 7.5 confirmed cases/million. Diagonal grey lines indicate a doubling in the infection rate every 2, 4, or 8 days. To hide a country, click on the country in the plot legend. Clicking again on the country in the legend will restore the data within the plot. Countries are shown in order of the date at which they passed the 4 confirmed case/million mark. Regions are as defined by the UN with some regions lumped together if only a few data points were available. Due to the large number of countries shown, you may need to scroll through the legend. Regions of the plot are also able to be zoomed interactively. Please note the y-axis is shown on the logarithmic scale, so that a series of points which appear to be diagonal will indicate exponential growth. The flatter the line, the slower the growth and a perfectly horizontal line would indicate zero growth, or no new confirmed cases.
minPop <- 5e6
minRate <- 12
ggplotly(
confirmed %>%
group_by(Country, date) %>%
summarise(confirmed = sum(confirmed)) %>%
mutate(
`daily total` = c(0, diff(confirmed)),
daily_ma = sma(`daily total`, 7)
) %>%
ungroup() %>%
dplyr::filter(`daily total` > 0 | confirmed > 0) %>%
inner_join(
dplyr::filter(
wikiPops, Population > minPop | Country %in% alwaysShow
)
) %>%
mutate(
`Daily Rate` = round(1e6 * daily_ma / Population, 2),
Region = str_replace_all(
Region, "(Central|Southern) Asia", "Central & Southern Asia"
),
# Region = str_replace_all(
# Region, "(Eastern|South-eastern) Asia", "Eastern & South-Eastern Asia"
# ),
Region = str_replace_all(
Region, "(Northern America|Caribbean)", "Caribbean & Northern America"
),
Region = str_replace_all(Region, "(.+) Africa", "Africa (All Regions)"),
Region = fct_lump(Region, n = 11)
) %>%
group_by(Country) %>%
dplyr::filter(
date > "2020-03-01",
date < dt,
max(`Daily Rate`) > minRate | Country %in% alwaysShow
) %>%
ungroup() %>%
rename_all(str_to_title) %>%
mutate(
`Population (millions)` = round(Population / 1e6, 2)
) %>%
ggplot(
aes(Date, `Daily Rate`, colour = Country, label = `Daily Total`, key = `Population (millions)`)
) +
geom_line() +
facet_wrap(
~Region, ncol = 3, scales = "free_y"
) +
labs(
y = "Daily New Confirmed Cases (per million)"
) +
scale_x_date(expand = expansion(c(0, 0.03))) +
scale_y_continuous(expand = expansion(c(0, 0.05))) +
scale_colour_manual(values = countryCols)
) %>%
shiftAxisLabel()
Daily New Confirmed Cases (per million) using each country’s population to calculate the case rate. 7 day Simple Moving Averages are used to plot daily case rates in order to minimise the impact of single-day spikes and irregular reporting. Daily Totals provided when hovering are the reported number of cases for that specific day, without smoothing or scaling. Only countries with more than 4,000,000 people and where the daily rate exceeded 12 cases/million are shown.
An alternate viewpoint on the data is to remove time and inspect the relationship between the daily increase in cases and the total number of cases. When this relationship ceases it’s near linear relationship, this can be a sign the control measures have begun to take effect. Whilst this relationship appears to have broken down for Australia, no breakdown has yet occurred for countries such as South Africa, USA and Brazil, with these countries explicitly still in, or having resumed the exponential growth phase.
minPop <- 8e6
minDays <- 10
minRate <- 50
plotIncVConf <- confirmed %>%
group_by(Country, date) %>%
summarise_at(vars(confirmed), sum) %>%
dplyr::filter(confirmed > 0) %>%
inner_join(
dplyr::filter(wikiPops, Population > minPop | Country %in% alwaysShow)
) %>%
mutate(
rate = 1e6 * confirmed / Population
) %>%
split(f = .$Country) %>%
lapply(function(x, n = 7){
x %>%
mutate(
d = c(0, diff(rate))
) %>%
mutate_at(
vars(d), sma, n = n
) %>%
dplyr::filter(
!is.na(d),
rate > minRate
) %>%
mutate(
nDays = nrow(.)
)
}
) %>%
bind_rows() %>%
ungroup() %>%
dplyr::filter(
nDays > minDays,
d > 0.01
) %>%
arrange(date) %>%
mutate(
Region = str_replace_all(
Region, "(Southern|Western) Europe", "Southern & Western Europe"
),
Region = str_replace_all(
Region, "(Central|Southern) Asia", "Central & Southern Asia"
),
Region = str_replace_all(
Region, "(Central America|Northern America|Caribbean)", "Caribbean, Central & Northern America"
),
Region = str_replace_all(
Region, "(Eastern|Middle|Southern) Africa", "Eastern, Middle & Southern Africa"
),
Country = fct_inorder(Country),
rate = round(rate, 2),
d = round(d, 3),
Population = comma(round(Population, -3)),
Region = fct_lump(Region, n = 11)
) %>%
rename(
Rate = rate,
`Average Daily Increase` = d,
Date = date
) %>%
ggplot(
aes(Rate, `Average Daily Increase`, colour = Country, label = Population, key = Date)
) +
geom_line() +
scale_y_log10(
name = "Average Daily Increase (Cases / Million)",
label = label_comma(accuracy = 0.1)) +
scale_x_log10(
name = "Cumulative Confirmed Infection Rate (Cases / Million)"
) +
scale_colour_manual(values = countryCols) +
facet_wrap(~Region, ncol = 3)
capIncVConf <- glue(
"*Daily Increase in Cases plotted against Confirmed Cases, using confirmed cases / million.
These two values are directly proportional until interventions are successful, at which point the proportional relationship changes, as evidenced by a sudden downwards turn.
Scaling by population aids in the visualisation of where in the relative infection trajectory each country's control measures have begun to take effect.
Daily increases are shown using a 7-day simple moving average in order to minimise the impact of day-to-day variation.
Countries are only shown from the point at which the moving average exceeds {minRate} cases/million, and have exceeded this value for > {minDays} days.
Regions are as defined by the UN with some combined for convenience if only a small number of countries were available.
Data is additionally restricted to countries with a population > {comma(minPop)}.*
"
)
ggplotly(plotIncVConf +
coord_cartesian(
ylim = c(0.5, max(plotIncVConf$data$`Average Daily Increase`)))
) %>%
shiftAxisLabel(1.5)
Daily Increase in Cases plotted against Confirmed Cases, using confirmed cases / million. These two values are directly proportional until interventions are successful, at which point the proportional relationship changes, as evidenced by a sudden downwards turn. Scaling by population aids in the visualisation of where in the relative infection trajectory each country’s control measures have begun to take effect. Daily increases are shown using a 7-day simple moving average in order to minimise the impact of day-to-day variation. Countries are only shown from the point at which the moving average exceeds 50 cases/million, and have exceeded this value for > 10 days. Regions are as defined by the UN with some combined for convenience if only a small number of countries were available. Data is additionally restricted to countries with a population > 8,000,000.
minPop <- 4e6
totalConf <- confirmed %>%
group_by(Country) %>%
dplyr::filter(date == max(date)) %>%
ungroup() %>%
summarise_at(vars(confirmed), sum) %>%
pull(confirmed)
confirmed %>%
group_by(Country) %>%
dplyr::filter(date == max(date)) %>%
group_by(Country, date) %>%
summarise_at(vars(confirmed), sum) %>%
ungroup() %>%
inner_join(wikiPops) %>%
dplyr::filter(Population > minPop) %>%
mutate(
`Infection Rate` = 1e6*confirmed / Population,
TotalRank = rank(1/confirmed),
RateRank = rank(1/`Infection Rate`),
AveRank = (TotalRank + RateRank) / 2
) %>%
arrange(desc(RateRank)) %>%
mutate(
Country = fct_inorder(Country)
) %>%
arrange(AveRank) %>%
dplyr::slice(1:25) %>%
droplevels() %>%
mutate(
Continent = fct_inorder(as.character(Continent))
) %>%
dplyr::select(-contains("Rank")) %>%
pivot_longer(
cols = c(confirmed, `Infection Rate`),
names_to = "name",
values_to = "value"
) %>%
mutate(
lab_y = case_when(
name == "confirmed" ~ value + 2.75e5,
name != "confirmed" ~ value + 1.2e3
)
) %>%
ggplot(aes(Country, value, fill = Country)) +
geom_col(colour = "black") +
geom_label(
aes(y = lab_y, label = comma_format(1)(value)),
alpha = 0.3
) +
facet_grid(
Continent~name,
scales = "free", space = "free_y",
labeller = as_labeller(
c(
`Infection Rate` = "Confirmed Cases / Million",
confirmed = "Total Confirmed Cases",
structure(levels(wikiPops$Continent), names = levels(wikiPops$Continent))
)
),
switch = "x"
) +
coord_flip() +
scale_fill_viridis_d(option = "magma") +
scale_y_continuous(labels = comma, expand = expansion(c(0, 0.1))) +
theme(
axis.title = element_blank(),
legend.position = "none",
panel.spacing.x = unit(0.02, "npc"),
strip.text = element_text(face = "bold"),
strip.placement = "outside"
)
Most impacted 25 countries when combining rankings across both total confirmed cases, and total confirmed cases/million. Only countries with a population greater than 4,000,000 are shown. At the time of preparation, the total number of global infections stands at 10,694,071.
fr <- confirmed %>%
inner_join(deaths) %>%
group_by(Country) %>%
dplyr::filter(date == max(date)) %>%
ungroup() %>%
summarise(fr = sum(deaths) / sum(confirmed)) %>%
.[["fr"]]
The current fatality rate from all confirmed cases is 4.8%. This may be a function of under-reporting of true cases and is very likely to be an overestimate.
minPop <- 4e6
minCases <- 1000
deaths %>%
left_join(confirmed) %>%
group_by(Country, date) %>%
summarise_at(vars(deaths, confirmed), sum) %>%
dplyr::filter(deaths > 0) %>%
left_join(wikiPops) %>%
ungroup() %>%
mutate(
infectionRate = round(1e6 * confirmed / Population, 1),
fatalityRate = deaths / confirmed,
fpm = round(1e6 * deaths / Population, 1),
Population = round(Population / 1e6, 3)
) %>%
arrange(desc(date), fatalityRate) %>%
distinct(Country, .keep_all = TRUE) %>%
arrange(desc(fpm)) %>%
dplyr::select(
Continent, Region, Country, Population,
`Confirmed Cases` = confirmed,
`Cases / Million` = infectionRate,
`Total Fatalities` = deaths,
`Fatalities / Million` = fpm,
`% Fatal Infections` = fatalityRate
) %>%
datatable(
options = list(
pageLength = 25,
autoWidth = TRUE,
searchCols = list(
NULL, NULL, NULL,
list(
search = glue(
'{minPop/1e6} ... {max(wikiPops$Population/1e6)}'
)
),
list(
search = glue(
'{minCases} ... {max(.$`Confirmed Cases`)}'
)
),
NULL, NULL, NULL
)
),
filter = 'top',
class = "stripe",
rownames = FALSE,
caption = glue(
"All countries with recorded fatalities, sorted by default in decreasing order of the Fatality Rate.
The Fatality Rate simply indicates the number of confirmed cases which end in a fatality.
The Infection Rate represents the cumulative number of cases confirmed within the country, per million people.
All columns are searchable and filters are set by default to exclude countries with populations below {comma(minPop)} and those with fewer than {minCases} confirmed cases."
)
) %>%
formatRound(
columns = "Cases / Million",
mark = ",",
digits = 1
) %>%
formatRound(
columns = "Total Fatalities",
mark = ",",
digits = 0
) %>%
formatPercentage(
columns = "% Fatal Infections",
digits = 2
)
minRate <- 2
minDays <- 24
minPop <- 5e6
scaledDeathPlot <- deaths %>%
group_by(Country, date) %>%
summarise_at(vars(deaths), sum) %>%
ungroup() %>%
dplyr::filter(deaths > 0) %>%
right_join(
wikiPops %>%
dplyr::filter(Population > minPop | Country %in% alwaysShow)
) %>%
mutate(
rate = round(1e6 * deaths / Population, 2)
) %>%
dplyr::filter(rate > minRate) %>%
group_by(Country) %>%
mutate(Days = as.integer(date - min(date))) %>%
dplyr::filter(
max(Days) > minDays | Country %in% alwaysShow
) %>%
arrange(desc(Days)) %>%
ungroup() %>%
mutate(
Region = str_replace_all(
Region, "(Southern|Western) Europe", "Southern & Western Europe"
),
Region = str_replace_all(
Region, "(Central|Southern) Asia", "Central & Southern Asia"
),
Region = str_replace_all(
Region, "(Central America|Northern America|Caribbean)", "Caribbean, Central & Northern America"
),
Region = str_replace_all(
Region, "(Eastern|Middle|Southern) Africa", "Eastern, Middle & Southern Africa"
),
Country = fct_inorder(Country),
Region = fct_lump(Region, n = 11),
`One Death Every` = round(Population / deaths, 0),
deaths = comma(deaths),
`Population (millions)` = round(Population / 1e6, 1)
) %>%
rename_all(str_to_title) %>%
rename_all(str_replace_all, pattern = "Mill", replacement = "mill") %>%
ggplot(
aes(
x = Days, y = Rate, colour = Country, key = Date,
b = `Population (millions)`, label = Deaths,
family = `One Death Every`
)
) +
geom_line() +
scale_y_log10() +
scale_colour_manual(values = countryCols) +
labs(
x = glue("Days Since Passing {minRate} Deaths / Million"),
y = "Deaths / Million"
) +
facet_wrap(~Region, ncol = 3, scales = "free_y")
scaledDeathPlot %>%
ggplotly(
tooltip = c("Country", "Date", "Rate", "Deaths", "One Death Every", "Population (millions)")
) %>%
shiftAxisLabel(1.5)
Cumulative fatalities for all countries with a population greater than 5 million, who passed 2 deaths / million more than 24 days ago. In the legend at right, countries are shown in order of passing 2 deaths / million. Regions are shown as defined by the UN, however some with fewer points may have been merged for convenience.
minPop <- 5e6
minRate <- 0.1
n <- 7
ggplotly(
deaths %>%
group_by(Country, date) %>%
summarise_at(vars(deaths), sum) %>%
mutate(
daily = c(0, diff(deaths)),
MA = sma(daily, n)
) %>%
inner_join(wikiPops) %>%
ungroup() %>%
dplyr::filter(
Population > minPop | Country %in% alwaysShow,
!is.na(MA),
deaths > 0
) %>%
arrange(date) %>%
mutate(
rate = round(1e6 * MA / Population, 2),
Region = as.character(Region),
Region = str_replace_all(
Region, "(Central|Southern) Asia", "Central & Southern Asia"
),
Region = str_replace_all(
Region, "(Eastern|South-eastern) Asia", "Eastern & South-Eastern Asia"
),
Region = str_replace_all(
Region, "(Central America|Northern America|Caribbean)", "Caribbean, Central & Northern America"
),
Region = str_replace_all(
Region, "(Western|Northern) Africa", "Western & Northern Africa"
),
Region = str_replace_all(
Region, "(Eastern|Middle|Southern) Africa", "Eastern, Middle & Southern Africa"
),
Region = fct_lump(Region, n = 11),
Country = fct_inorder(Country),
`Population (millions)` = round(Population / 1e6, 2)
) %>%
group_by(Country) %>%
dplyr::filter(max(rate) > minRate) %>%
dplyr::rename(
Date = date,
`Daily Fatility Rate` = rate,
`Actual Daily Total` = daily
) %>%
ggplot(
aes(Date, `Daily Fatility Rate`, colour = Country, label = `Population (millions)`, key = `Actual Daily Total`)
) +
geom_line() +
facet_wrap(~Region, ncol = 3, scales = "free_y") +
scale_colour_manual(values = countryCols) +
labs(
y = "Average Daily Fatalities (per million)"
)
) %>%
shiftAxisLabel(1.5)
Average daily fatality rate (per million) using a 7-day moving average. Only countries with a population greater than 5,000,000 and a daily fatality rate that has exceeded 0.1 deaths/million are included. Clicking the Autoscale icon can be very helpful for this visualisation.
minPop <- 4e6
minDays <- 14
minRate <- 1
minD <- 0.45
dailyVsTotalDeaths <- deaths %>%
group_by(Country, date) %>%
summarise_at(vars(deaths), sum) %>%
dplyr::filter(deaths > 0) %>%
split(f = .$Country) %>%
lapply(function(x, n = 7){
x %>%
mutate(
d = c(0, diff(deaths))
) %>%
mutate_at(
vars(deaths, d), sma, n = n
)
}
) %>%
bind_rows() %>%
inner_join(wikiPops) %>%
mutate(
deaths = 1e6 * deaths / Population,
d = 1e6 * d / Population,
max_d = max(d, na.rm = TRUE)
) %>%
ungroup() %>%
dplyr::filter(!is.na(deaths), !is.na(d)) %>%
mutate_at(vars(deaths, d), round, 2) %>%
dplyr::filter(
Population > minPop | Country %in% alwaysShow,
max_d > minD | Country %in% alwaysShow,
deaths > minRate,
d > 0
) %>%
group_by(Country) %>%
mutate(n = n()) %>%
ungroup() %>%
dplyr::filter(n > minDays | Country %in% alwaysShow) %>%
rename_all(str_to_title) %>%
rename(
`Daily Fatalities` = D,
`Total Fatalities` = Deaths
) %>%
arrange(Date) %>%
mutate(
Population = comma(round(Population, -3)),
Country = fct_inorder(Country),
Region = str_replace_all(Region, "(Caribbean|Northern America)", "Caribbean & Northern America"),
Region = fct_lump(Region, n = 11)
) %>%
ggplot(aes(`Total Fatalities`, `Daily Fatalities`, colour = Country, label = Date, key = Population)) +
geom_line() +
scale_x_log10(labels = label_comma(accuracy = 1)) +
scale_y_log10(labels = label_comma(accuracy = 0.01), limits = c(0.01, NA)) +
scale_colour_manual(values = countryCols) +
facet_wrap(~Region, ncol = 3, scales = "free_y") +
labs(
x = "Total Fatalities (per million)",
y = "Daily Fatalities (per million)"
)
capDailyVsTotal <- glue(
"*Daily Fatalities plotted against Total Fatalities, scaled by population size using Fatalities / Million.
These two values are directly proportional until interventions are successful, at which point the proportional relationship changes, as evidenced by a sudden downwards turn.
Values shown are 7-day simple moving averages in order to minimise the impact of day-to-day variation.
Countries are only shown from the point at which the moving average exceeds {minRate} fatality per million people, and has exceeded this value for > {minDays} days.
Data is additionally restricted to countries with a population > {comma(minPop)}, and those who at one point were recording > {minD} daily fatalities / million.
Importantly, __due to the time taken from the initial infection to the day of death, this is a lag indicator of the control of infection__.*
"
)
ggplotly(
dailyVsTotalDeaths
) %>%
shiftAxisLabel(1.6)
Daily Fatalities plotted against Total Fatalities, scaled by population size using Fatalities / Million. These two values are directly proportional until interventions are successful, at which point the proportional relationship changes, as evidenced by a sudden downwards turn. Values shown are 7-day simple moving averages in order to minimise the impact of day-to-day variation. Countries are only shown from the point at which the moving average exceeds 1 fatality per million people, and has exceeded this value for > 14 days. Data is additionally restricted to countries with a population > 4,000,000, and those who at one point were recording > 0.45 daily fatalities / million. Importantly, due to the time taken from the initial infection to the day of death, this is a lag indicator of the control of infection.
nCnt <- 25
topDeaths <- deaths %>%
dplyr::filter(deaths > 0) %>%
group_by(Country, date) %>%
summarise_at(vars(deaths), sum) %>%
dplyr::filter(
deaths == max(deaths),
date == max(date)
) %>%
ungroup() %>%
inner_join(wikiPops) %>%
mutate(
rate = 1e6*deaths / Population,
totalRank = nrow(.) - rank(deaths) + 1,
rateRank = nrow(.) - rank(rate) + 1,
aveRank = (totalRank + rateRank)/2
) %>%
arrange(aveRank, desc(Population)) %>%
dplyr::slice(1:nCnt) %>%
arrange(desc(rateRank)) %>%
mutate(Country = fct_inorder(Country)) %>%
arrange(rateRank) %>%
mutate(Continent = fct_inorder(as.character(Continent)))
a <- topDeaths %>%
ggplot(aes(Country, rate, fill = Country)) +
geom_col(colour = "black") +
geom_label(
aes(y = rate + 50, label = round(rate, 0)),
fill = "white", alpha = 0.5
) +
scale_fill_viridis_d(option = "magma", direction = 1) +
scale_y_continuous(expand = expansion(c(0, 0.08))) +
labs(y = "Fatalities / Million") +
coord_flip() +
facet_grid(Continent~., scales = "free_y", space = "free_y") +
theme(legend.position = "none")
b <- topDeaths %>%
ggplot(aes(Country, deaths, fill = Country)) +
geom_col(colour = "black") +
geom_label(
aes(y = deaths + 10000, label = comma(deaths, accuracy = 1)),
fill = "white", alpha = 0.5
) +
scale_fill_viridis_d(option = "magma", direction = 1) +
scale_y_continuous(expand = expansion(c(0, 0.08)), labels = comma) +
labs(y = "Total Fatalities") +
coord_flip() +
facet_grid(Continent~., scales= "free_y", space = "free_y") +
theme(legend.position = "none")
cp <- glue(
"*Comparison of the {nrow(a$data)} most impacted countries.
Countries were ranked by total fatalities and by fatalities / million, with the {nrow(a$data)} most highly ranked across both methods are shown.
Fatalities are shown using A) the number of fatalities scaled by population size (Fatalities / Million) and B) Total Fatalities.
Countries are also grouped by their continent as designated by the UN classifications, and within each continent each country is ordered by Fatalities / Million.
For fatality rates scaled by population size, it is important to realise that a value of 500 indicates that one in every 2000 people from the total population has died (ignoring demographics).
Similarly, a value of 100 indicates that 1 in every 10,000 from the total population has died in that country.
Whilst the US currently has the most fatalities, 1 in every {comma(round(1e6 / dplyr::filter(a$data, Country == 'US')$rate, 0))} from the US population have currently been confirmed to have died from COVID19.
For {as.character(a$data$Country[which.max(a$data$rate)])}, 1 in every {comma(round(1e6 / max(a$data$rate), 0))} people are recorded as having died from COVID 19.
Importantly, whilst the fatality count in countries like the US and the UK are below the statistical value of 'excess deaths' observed throughout these countries, this is not true for Belgium and the fatality rate for Belgium is more likely to reflect an accurate assessment of the true fatalities due to COVID-19.
In contrast, the values for the US and the UK are likely to be under-estimates of the true fatalities.*"
)
plot_grid(
a + theme(legend.position = "none"),
b +
theme(
legend.position = "none",
axis.title.y = element_blank()
),
labels = c("A", "B"),
nrow = 1
)
Comparison of the 25 most impacted countries. Countries were ranked by total fatalities and by fatalities / million, with the 25 most highly ranked across both methods are shown. Fatalities are shown using A) the number of fatalities scaled by population size (Fatalities / Million) and B) Total Fatalities. Countries are also grouped by their continent as designated by the UN classifications, and within each continent each country is ordered by Fatalities / Million. For fatality rates scaled by population size, it is important to realise that a value of 500 indicates that one in every 2000 people from the total population has died (ignoring demographics). Similarly, a value of 100 indicates that 1 in every 10,000 from the total population has died in that country. Whilst the US currently has the most fatalities, 1 in every 2,570 from the US population have currently been confirmed to have died from COVID19. For Belgium, 1 in every 1,183 people are recorded as having died from COVID 19. Importantly, whilst the fatality count in countries like the US and the UK are below the statistical value of ‘excess deaths’ observed throughout these countries, this is not true for Belgium and the fatality rate for Belgium is more likely to reflect an accurate assessment of the true fatalities due to COVID-19. In contrast, the values for the US and the UK are likely to be under-estimates of the true fatalities.
minDays <- 40
minPop <- 4e6
startingPoint <- 2
df <- confirmed %>%
inner_join(deaths) %>%
group_by(Country, date) %>%
summarise_at(
vars(confirmed, deaths),
sum
) %>%
inner_join(
wikiPops %>% dplyr::filter(Population > minPop | Country %in% alwaysShow)
) %>%
ungroup() %>%
mutate(
`Infection Rate` = 1e6 * confirmed / Population,
f = 1e6 * deaths / Population
) %>%
dplyr::filter(
f > startingPoint
# `Infection Rate` > startingPoint
) %>%
group_by(Country) %>%
mutate(
Days = date - min(date),
n = n()
) %>%
dplyr::filter(
n > minDays,
max(deaths, na.rm = TRUE) > 0
) %>%
mutate(
Rate = deaths / confirmed,
`Fatality Rate` = percent(Rate, accuracy = 0.1),
minusT = date - max(date)
) %>%
ungroup()
plotFr <- mutate(
df,
Country = factor(
Country,
levels = df %>%
dplyr::select(Country, minusT, Rate) %>%
pivot_wider(
id_cols = Country,
names_from = minusT,
values_from = Rate
) %>%
as.data.frame() %>%
column_to_rownames("Country") %>%
dist() %>%
hclust() %>%
as.dendrogram() %>%
labels()
)
) %>%
rename_all(str_to_title) %>%
mutate(`Population (millions)` = round(Population / 1e6, 2)) %>%
ggplot(
aes(
x = Days, y = Country, fill = Rate,
conf = Confirmed,
deaths = Deaths,
date = Date,
label = `Fatality Rate`,
key = `Population (millions)`
)
) +
geom_raster() +
geom_vline(
aes(xintercept = Days + 0.5),
data = . %>%
dplyr::filter(Country == "Australia") %>%
dplyr::filter(Date == max(Date)),
linetype = 3,
size = 1/3,
colour = "grey70"
) +
scale_fill_viridis_c(
option = "magma"
) +
scale_x_continuous(
expand = expansion(0, 0),
labels = abs
) +
scale_y_discrete(expand = expansion(0, 0)) +
labs(
x = glue(
"Days since passing {startingPoint} fatalities/million"
),
y = c(),
fill = "Fatality\nRate"
) +
theme(
panel.grid = element_blank()
)
cpFr <- glue(
"*Fatality Rate from confirmed cases after passing {startingPoint} fatalities / million.
Only countries with {minDays} days of data beyond this time-point and a population size >{comma(minPop)} are shown.
Country order is based on clustering using the most recent values.
Countries with no recorded fatalities have been excluded for obvious reasons.
The dashed grey line indicates the time-point Australia is currently at.
A clear trend of an increasing fatality rate with time is evident in many countries (e.g. Spain, France, Italy, UK), however, for some countries (e.g. Singapore) this rate appears relatively stable throughout the majority of days.
The overall Fatality Rate for confirmed cases is currently ({percent(fr, accuracy = 0.1)}).*"
)
ggplotly(
plotFr ,
tooltip = c(
"Country", "Date", "Days", "Confirmed", "Deaths",
"Fatality Rate", "Population (millions)"
)
)
Fatality Rate from confirmed cases after passing 2 fatalities / million. Only countries with 40 days of data beyond this time-point and a population size >4,000,000 are shown. Country order is based on clustering using the most recent values. Countries with no recorded fatalities have been excluded for obvious reasons. The dashed grey line indicates the time-point Australia is currently at. A clear trend of an increasing fatality rate with time is evident in many countries (e.g. Spain, France, Italy, UK), however, for some countries (e.g. Singapore) this rate appears relatively stable throughout the majority of days. The overall Fatality Rate for confirmed cases is currently (4.8%).
rr <- confirmed %>%
group_by(Country, date) %>%
summarise_at(vars(confirmed), sum, na.rm = TRUE) %>%
left_join(
recovered %>%
group_by(Country, date) %>%
summarise_at(vars(recovered), sum, na.rm = TRUE)
) %>%
dplyr::filter(date == max(date)) %>%
ungroup() %>%
summarise(rr = sum(recovered) / sum(confirmed)) %>%
.[["rr"]]
predRR <- confirmed %>%
group_by(Country) %>%
dplyr::filter(
date == max(date)
) %>%
ungroup() %>%
left_join(predRecovered) %>%
group_by(Country, date) %>%
summarise_at(vars(confirmed, recovered), sum, na.rm = TRUE) %>%
ungroup() %>%
summarise(rr = sum(recovered) / sum(confirmed)) %>%
.[["rr"]]
Information regarding recovered cases is likely to be the least reliable of reported values as many regions do not report updated numbers for several consecutive days. Additionally many regions do not report recovered cases as the criteria for considering a person to have recovered as currently unclear. Given this:
minDays <- 30
startingPoint <- 4
minPop <- 5e6
df <- confirmed %>%
dplyr::filter(
confirmed > 0,
Country != "China (Other)"
) %>%
left_join(deaths) %>%
group_by(Country, date) %>%
summarise_at(
vars(confirmed, deaths), sum
) %>%
inner_join(
recovered %>%
group_by(Country, date) %>%
summarise_at(vars(recovered), sum)
) %>%
mutate_at(vars(confirmed, deaths, recovered), cummax) %>%
mutate(
active = confirmed - deaths - recovered
) %>%
dplyr::filter(!is.na(active)) %>%
inner_join(
dplyr::filter(wikiPops, Population > minPop | Country %in% alwaysShow)
) %>%
mutate(
rate = 1e6 * active / Population,
pass = cummax(rate > startingPoint)
) %>%
dplyr::filter(pass > 0) %>%
group_by(Country) %>%
mutate(
days = date - min(date)
) %>%
dplyr::filter(max(days) > minDays | Country %in% alwaysShow) %>%
dplyr::filter(max(recovered) > 0) %>%
ungroup() %>%
mutate(
days = as.integer(days),
rate = round(rate, 2)
) %>%
arrange(date) %>%
mutate(
Region = str_replace_all(
Region, "(Southern|Western) Europe", "Southern & Western Europe"
),
Region = str_replace_all(
Region, "(Central|Southern) Asia", "Central & Southern Asia"
),
Region = str_replace_all(
Region, "(Central America|Northern America|Caribbean)", "Caribbean, Central & Northern America"
),
Region = str_replace_all(
Region, "(Eastern|Middle|Southern) Africa", "Eastern, Middle & Southern Africa"
),
Country = fct_inorder(Country),
Region = fct_lump(Region, n = 11)
) %>%
rename_all(str_to_title)
nDays <- max(df$Days)
p2 <- df %>%
ggplot(
aes(
x = Days, y = Rate, colour = Country,
Date = Date, Active = Active,
Confirmed = Confirmed, Recovered = Recovered,
Deaths = Deaths
)
) +
geom_line() +
scale_x_continuous(
expand = expansion(mult = c(0, 0.05)),
) +
scale_y_log10(
expand = expansion(mult = c(0, 0.05)),
labels = comma_format(accuracy = 1),
breaks = 10^seq(1, 4)
) +
scale_colour_manual(values = countryCols) +
xlab(
paste(
"Days since passing",
startingPoint,
"confirmed active cases/million"
)
) +
ylab("Confirmed Active Infection Rate (cases/million)") +
facet_wrap(~Region, ncol = 3)
ggplotly(
p2 +
coord_cartesian(ylim = c(1, max(p2$data$Rate)))
) %>%
shiftAxisLabel(1.8)
Confirmed active cases of COVID-19 for countries where the confirmed infection rate has exceeded 4 confirmed active cases/million for more than 161 calendar days. Only countries with a population greater than 5,000,000 are shown for better visualisation. Due to difficulties introduced by the currently reported low active infection rate outside Hubei province, data from China has been excluded from this plot, with the exception of Hubei and Hong Kong. Recovered cases are poorly and irregularly reported by many countries (e.g. Ireland, Serbia & Norway). Some countries, such as Sweden, are not reporting recovered cases and these countries have been excluded from this plot. As a result, this plot may indicate multiple instances of a sudden decline which are a simple artefact of data release schedules. To hide a country, click on the country in the plot legend. Clicking again on the country in the legend will restore the data within the plot. Countries are shown in order of the date at which they passed the 4 confirmed active case/million mark. Due to the number of countries shown, you may need to scroll through the legend. Regions of the plot are also able to be zoomed interactively. Please note the y-axis is shown on the logarithmic scale, so that a series of points which appear to be diagonal will indicate exponential growth/decay. Given the different starting point to the previous plot, data will generally be shown for fewer time-points.
df <- confirmed %>%
dplyr::filter(
confirmed > 0,
Country != "China (Other)"
) %>%
left_join(deaths) %>%
group_by(Country, date) %>%
summarise_at(
vars(confirmed, deaths), sum
) %>%
inner_join(
predRecovered %>%
group_by(Country, date) %>%
summarise_at(vars(recovered), sum)
) %>%
mutate_at(vars(confirmed, deaths, recovered), cummax) %>%
mutate(
active = confirmed - deaths - recovered
) %>%
dplyr::filter(!is.na(active)) %>%
inner_join(
dplyr::filter(wikiPops, Population > minPop | Country %in% alwaysShow)
) %>%
mutate(
rate = 1e6 * active / Population,
pass = cummax(rate > startingPoint)
) %>%
dplyr::filter(pass > 0) %>%
group_by(Country) %>%
mutate(
days = date - min(date)
) %>%
dplyr::filter(max(days) > minDays | Country %in% alwaysShow) %>%
dplyr::filter(max(recovered) > 0) %>%
ungroup() %>%
mutate(
days = as.integer(days),
rate = round(rate, 2)
) %>%
arrange(date) %>%
mutate(
Region = str_replace_all(
Region, "(Southern|Western) Europe", "Southern & Western Europe"
),
Region = str_replace_all(
Region, "(Central|Southern) Asia", "Central & Southern Asia"
),
Region = str_replace_all(
Region, "(Central America|Northern America|Caribbean)", "Caribbean, Central & Northern America"
),
Region = str_replace_all(
Region, "(Eastern|Middle|Southern) Africa", "Eastern, Middle & Southern Africa"
),
Country = fct_inorder(Country),
Region = fct_lump(Region, n = 11)
) %>%
rename_all(str_to_title)
nDays <- max(df$Days)
p2 <- df %>%
ggplot(
aes(
x = Days, y = Rate, colour = Country,
Date = Date, Active = Active,
Confirmed = Confirmed, Recovered = Recovered,
Deaths = Deaths
)
) +
geom_line() +
scale_x_continuous(
expand = expansion(mult = c(0, 0.05)),
) +
scale_y_log10(
expand = expansion(mult = c(0, 0.05)),
labels = comma_format(accuracy = 1),
breaks = 10^seq(1, 4)
) +
scale_colour_manual(values = countryCols) +
xlab(
paste(
"Days since passing",
startingPoint,
"predicted active cases/million"
)
) +
ylab("Predicted Active Infection Rate (cases/million)") +
facet_wrap(~Region, ncol = 3)
ggplotly(
p2 +
coord_cartesian(ylim = c(1, max(p2$data$Rate)))
) %>%
shiftAxisLabel(1.8)
Predicted active cases of COVID-19 for countries where the active infection rate has exceeded 4 predicted active cases/million for more than 140 calendar days. Predicted recovered cases are obtained using the median recovery time of 21 days, accounting for fatal cases. This allows for assessment of countries where recovered cases are poorly reported. Only countries with a population greater than 5,000,000 are shown for better visualisation. Due to difficulties introduced by the currently reported low active infection rate outside Hubei province, data from China has been excluded from this plot, with the exception of Hubei and Hong Kong. To hide a country, click on the country in the plot legend. Clicking again on the country in the legend will restore the data within the plot. Countries are shown in order of the date at which they passed the 4 predicted active case/million mark. Due to the number of countries shown, you may need to scroll through the legend. Regions of the plot are also able to be zoomed interactively. Please note the y-axis is shown on the logarithmic scale, so that a series of points which appear to be diagonal will indicate exponential growth/decay. Given the different starting point to the previous plot, data will generally be shown for fewer time-points.
minPop <- 8e6
p4 <- confirmed %>%
dplyr::filter(
confirmed > 0
) %>%
left_join(deaths) %>%
group_by(Country, date) %>%
summarise_at(vars(confirmed, deaths), sum) %>%
dplyr::filter(date == max(date)) %>%
left_join(
recovered %>%
group_by(Country, date) %>%
summarise_at(vars(recovered), sum)
) %>%
ungroup() %>%
inner_join(
wikiPops %>% dplyr::filter(Population > minPop | Country %in% alwaysShow)
) %>%
mutate(rate = 1e6 * confirmed / Population) %>%
dplyr::filter(rate > startingPoint) %>%
group_by(Country) %>%
mutate(
active = confirmed - recovered - deaths,
active = 100*active / confirmed,
recovered = 100*recovered / confirmed,
fatalities = 100*deaths / confirmed
) %>%
dplyr::filter(max(recovered) > 1) %>%
ungroup() %>%
dplyr::filter(active < 100) %>%
arrange(active) %>%
mutate(Country = fct_inorder(Country)) %>%
pivot_longer(
cols = c(active, recovered, fatalities),
names_to = "Status",
values_to = "Percentage"
) %>%
mutate(
Status = str_to_title(Status),
Status = factor(
Status,
levels = c("Active", "Recovered", "Fatalities")
),
Percentage = round(Percentage, 2)
) %>%
mutate(confirmed = comma(confirmed)) %>%
rename(Confirmed = confirmed) %>%
ggplot(
aes(
Country, Percentage,
fill = Status, cases = Confirmed
)
) +
geom_col() +
scale_fill_manual(
values = c(
Active = "blue",
Recovered = "green",
Fatalities = "red"
)
) +
scale_y_continuous(expand = expansion(0, 0)) +
coord_flip() +
labs(x = c()) +
theme(
legend.position = "none"
)
ggplotly(p4)
Fatality, Recovery and Active Infection rates for countries which have exceeded 4 confirmed cases / million, and with a population size > 8,000,000. Countries are ordered by the percentage of cases that remain active. Only countries with a reported recovery rate > 1% are shown
ausPops <- tribble(
~State, ~Population,
"New South Wales", 8117976,
"Victoria", 6629870,
"Queensland", 5115451,
"South Australia", 1756494,
"Western Australia", 2630557,
"Tasmania", 535500,
"Northern Territory", 245562,
"Australian Capital Territory", 428060
)
Australian State populations were taken from the ABS Website and were accurate in Sept 2019. The difference with previous estimates used above was within 0.04%, and as such no adjustments were made.
A series of complimentary charts regarding the spread of COVID-19 are available from the ABC website.
confirmed %>%
dplyr::filter(
Country == "Australia",
date >= sort(unique(date), decreasing = TRUE)[2]
) %>%
bind_rows(
group_by(., date) %>%
summarise(
confirmed = sum(confirmed)
) %>%
mutate(
`Province/State` = "Total"
)
) %>%
group_by(`Province/State`) %>%
mutate(
Increase = c(NA, diff(confirmed)),
`% Increase` = c(NA, diff(confirmed)) / min(confirmed)
) %>%
ungroup() %>%
pivot_wider(
id_cols = `Province/State`,
names_from = date,
values_from = c(confirmed, Increase, `% Increase`)
) %>%
dplyr::select_if(function(x){sum(is.na(x)) <= 1}) %>%
rename(State = `Province/State`) %>%
rename_all(str_remove_all, pattern = "confirmed_") %>%
rename_all(str_remove_all, pattern = "_2020.+") %>%
left_join(
dplyr::select(latestAU, State, confirmed, deaths)
) %>%
mutate_at(
vars(confirmed, deaths),
function(x){
x[is.na(x)] <- sum(x, na.rm = TRUE)
x
}
) %>%
left_join(
auRecTS %>%
dplyr::filter(date == dt) %>%
dplyr::select(State = `Province/State`, recovered) %>%
bind_rows(tibble(State = "Total", recovered = sum(.$recovered)))
) %>%
mutate(
`% Increase` = percent(`% Increase`, accuracy = 0.01),
`Fatality Rate` = percent(deaths / confirmed, accuracy = 0.1),
`Recovery Rate` = percent(recovered / confirmed, accuracy = 0.1),
`Currently Active` = confirmed - recovered - deaths,
) %>%
rename(
Fatalities = deaths,
Recovered = recovered
) %>%
dplyr::select(
State, starts_with("20"), ends_with("Increase"), starts_with("Fatal"), starts_with("Recov"), `Currently Active`
) %>%
pander(
justify = "lrrrrrrrrr",
caption = paste(
"*Confirmed cases, fatalities and recoveries reported by each state at time of preparation.",
"Any states with unchanged, or decreasing confirmed cases may indicate delays with the automated data sources, such as health.gov.au or JHU, or that these states have not yet reported for the day.",
"Please note that some discrepancy with dates may occur due to automated data sources obtained different time zones, such as the USA, the UK and Australia.*"
),
emphasize.strong.rows = nrow(.)
)
| State | 2020-07-01 | 2020-07-02 | Increase | % Increase | Fatalities | Fatality Rate | Recovered | Recovery Rate | Currently Active |
|---|---|---|---|---|---|---|---|---|---|
| Australian Capital Territory | 108 | 108 | 0 | 0.00% | 3 | 2.8% | 105 | 97.2% | 0 |
| New South Wales | 3,203 | 3,211 | 8 | 0.25% | 51 | 1.6% | 3,026 | 94.2% | 134 |
| Northern Territory | 30 | 31 | 1 | 3.33% | 0 | 0.0% | 30 | 96.8% | 1 |
| Queensland | 1,067 | 1,067 | 0 | 0.00% | 6 | 0.6% | 1,059 | 99.3% | 2 |
| South Australia | 443 | 443 | 0 | 0.00% | 4 | 0.9% | 436 | 98.4% | 3 |
| Tasmania | 228 | 228 | 0 | 0.00% | 13 | 5.8% | 213 | 94.2% | 0 |
| Victoria | 2,231 | 2,303 | 72 | 3.23% | 20 | 0.9% | 1,866 | 81.0% | 417 |
| Western Australia | 611 | 611 | 0 | 0.00% | 9 | 1.5% | 598 | 97.9% | 4 |
| Total | 7,921 | 8,002 | 81 | 1.02% | 106 | 1.3% | 7,333 | 91.7% | 561 |
ausStatsCap <- "*Current confirmed and recovered cases, along with fatalities for Australia only. Active cases are shown as confirmed cases excluding fatalities and those classed as recovered. Loess curves through all points are shown as continuous lines. Data is only shown from 1^st^ March 2020 as this was the date of the first recorded fatality in Australia. Recovered patient information was also sparse in the early stages of data collection, and as a result estimates of active infections will be a significant underestimate until 6^th^ April. In particular, QLD only began reporting recovered cases on this date. NSW followed a fortnight after this date and as such, only the most recent numbers can be considered as accurate. Below this plot, the same figures can be seen broken down by state.*"
ggplotly(
confirmed %>%
dplyr::filter(Country == "Australia", confirmed > 0) %>%
left_join(deaths) %>%
left_join(recovered) %>%
mutate_at(vars(confirmed, deaths, recovered), na_locf) %>%
group_by(Country, date) %>%
summarise_at(vars(confirmed, deaths, recovered), sum) %>%
ungroup() %>%
mutate_at(vars(confirmed, deaths, recovered), cummax) %>%
mutate(active = confirmed - deaths - recovered) %>%
pivot_longer(
cols = c(active, confirmed, deaths, recovered),
names_to = "Status",
values_to = "Total"
) %>%
arrange(Status, date) %>%
dplyr::filter(date > ymd("2020-02-29")) %>%
mutate(
Status = str_to_title(Status),
Status = str_replace_all(Status, "Deaths", "Fatal"),
Status = factor(Status, levels = c("Recovered", "Active", "Fatal"))
) %>%
dplyr::filter(Total > 0) %>%
rename_all(str_to_title) %>%
dplyr::filter(Status != "Confirmed") %>%
ggplot(aes(Date, Total, fill = Status)) +
geom_col() +
geom_line(
data = . %>%
group_by(Date) %>%
summarise(
Total = sum(Total)
) %>%
mutate(Status = "Confirmed"),
colour = "blue"
) +
scale_fill_manual(
values = c(
Active = rgb(0, 0, 0),
Confirmed = rgb(0, 0.3, 0.7),
Fatal = rgb(0.8, 0.2, 0.2),
Recovered = rgb(0.2, 0.7, 0.4)
)
) +
scale_x_date(expand = expansion(c(0, 0.03))) +
scale_y_continuous(expand = expansion(c(0, 0.05))) +
labs("Total Cases")
)
Current confirmed and recovered cases, along with fatalities for Australia only. Active cases are shown as confirmed cases excluding fatalities and those classed as recovered. Loess curves through all points are shown as continuous lines. Data is only shown from 1st March 2020 as this was the date of the first recorded fatality in Australia. Recovered patient information was also sparse in the early stages of data collection, and as a result estimates of active infections will be a significant underestimate until 6th April. In particular, QLD only began reporting recovered cases on this date. NSW followed a fortnight after this date and as such, only the most recent numbers can be considered as accurate. Below this plot, the same figures can be seen broken down by state.
ggplotly(
confirmed %>%
dplyr::filter(Country == "Australia") %>%
left_join(deaths) %>%
left_join(recovered) %>%
mutate_at(vars(confirmed, deaths, recovered), na_locf) %>%
rename(State = `Province/State`) %>%
dplyr::filter(
date > ymd("2020-03-19"),
) %>%
arrange(date) %>%
group_by(State) %>%
mutate_at(
vars(confirmed, recovered, deaths), cummax
) %>%
ungroup() %>%
left_join(ausPops) %>%
mutate(active = confirmed - deaths - recovered) %>%
pivot_longer(
cols = c(confirmed, deaths, recovered, active),
names_to = "status",
values_to = "count"
) %>%
dplyr::filter(
count > 0,
!(State %in% c("Queensland", "New South Wales") & status == "recovered" & date < ymd("2020-04-06")),
!(State %in% c("South Australia") & status == "recovered" & date < ymd("2020-04-01")),
!(State %in% c("Tasmania") & status == "recovered" & date < ymd("2020-04-02")),
) %>%
dplyr::filter(status != "confirmed") %>%
mutate(
rate = 1e6*count/Population,
rate = round(rate, 2),
status = str_replace(status, "deaths", "fatal") %>% str_to_title(),
status = factor(status, levels = c("Recovered", "Active", "Fatal"))
) %>%
rename_all(str_to_title) %>%
ggplot(aes(Date, Rate, fill = Status, label = Count)) +
geom_col() +
geom_line(
data = . %>%
group_by(State, Date) %>%
summarise(
Rate = sum(Rate),
Count = sum(Count)
) %>%
mutate(Status = "Confirmed"),
colour = "blue"
) +
facet_wrap(~State, ncol = 4) +
scale_fill_manual(
values = c(
Active = rgb(0, 0, 0),
Confirmed = rgb(0, 0.3, 0.7),
Fatal = rgb(0.8, 0.2, 0.2),
Recovered = rgb(0.2, 0.7, 0.4)
)
) +
scale_x_date(expand = expansion(c(0, 0.03))) +
labs(y = "Rate (Cases / Million)")
)
Breakdown of individual states. Victorian recovered numbers began to be accurately reported from 22nd March, with other states gradually providing this information. NSW/QLD recovered cases have only recently begun being reported and up until the most recent dates, recovered/active values were very approximate for these states. The extreme drop for NSW active cases in early June is a function of the changed reporting strategy implemented by NSW Health.
ggplotly(
confirmed %>%
dplyr::filter(Country == "Australia") %>%
group_by(`Province/State`) %>%
mutate(daily = c(0, diff(confirmed))) %>%
ungroup() %>%
dplyr::filter(confirmed > 0) %>%
mutate(
daily = case_when(
daily < 0 ~ 0,
daily >= 0 ~ daily
)
) %>%
bind_rows(
group_by(., date) %>%
summarise(daily = sum(daily)) %>%
ungroup() %>%
mutate(`Province/State` = "All States")
) %>%
group_by(`Province/State`) %>%
mutate(
MA = round(sma(daily, 7), 2),
`Above Average` = daily > MA
) %>%
dplyr::filter(date > "2020-03-01") %>%
ggplot(aes(date, daily)) +
geom_col(
aes(fill = `Above Average`, colour = `Above Average`),
data = . %>% dplyr::filter(!is.na(`Above Average`)),
# fill = "grey80",
# colour = "grey50",
width = 1/2
) +
geom_line(aes(y = MA), colour = "blue") +
facet_wrap(~`Province/State`, scales = "free_y") +
labs(
x = "Date",
y = "Daily New Cases",
fill = "\nAbove\nAverage"
) +
scale_fill_manual(values = c("white", rgb(1, 0.2, 0.2))) +
scale_colour_manual(values = c("grey50", rgb(1, 0.2, 0.2))),
tooltip = c(
"date", "daily", "MA"
)
)
Daily new cases for each state shown against the 7-day average. Days which are above average are highlighted in red.
n <- 14
cp <- glue(
"*Growth factor for each State/Territory.
This value becomes volatile when daily new cases approach zero as is commonly observed in small populations, and at the end stages of an outbreak.
In order to try and minimise volatility a {n} day simple moving average was used, in contrast to the 5 day average as advocated [here](https://www.abc.net.au/news/2020-04-10/coronavirus-data-australia-growth-factor-covid-19/12132478).
This enables assessment of the growth factor over an entire quarantine period.
If no new cases are observed over this period, the value is not able to be calculated.
The dashed vertical lines indicate the day most state borders were closed.*"
)
gf <- list(
confirmed %>%
dplyr::filter(Country == "Australia") %>% #, date < dt) %>%
arrange(date) %>%
group_by(
`Province/State`
) %>%
mutate(
new = c(0, diff(confirmed)),
new_ma = sma(new, n)
) %>%
dplyr::filter(confirmed > 0, !is.na(new_ma)) %>%
mutate(
R = c(NA, new_ma[-1] / new_ma[-n()]),
R = case_when(
is.nan(R) ~ NA_real_,
!is.nan(R) ~ R
)
) %>%
ungroup() %>%
arrange(`Province/State`),
confirmed %>%
dplyr::filter(Country == "Australia") %>% #, date < dt) %>%
arrange(date) %>%
group_by(Country, date) %>%
summarise_at(vars(confirmed), sum) %>%
ungroup() %>%
mutate(
new = c(0, diff(confirmed)),
new_ma = sma(new, n)
) %>%
dplyr::filter(confirmed > 0, !is.na(new_ma)) %>%
mutate(
R = c(NA, new_ma[-1] / new_ma[-n()]),
R = case_when(
is.nan(R) ~ NA_real_,
!is.nan(R) ~ R
),
`Province/State` = "All States"
) %>%
arrange(`Province/State`)
) %>%
bind_rows() %>%
dplyr::filter(date > ymd("2020-03-15")) %>%
ggplot(aes(date, R, colour = `Province/State`)) +
geom_ribbon(aes(ymin = 1, ymax = R), alpha = 0.1) +
geom_hline(yintercept = 1) +
geom_vline(
xintercept = ymd("2020-03-22"),
linetype = 2,
colour = "grey30"
) +
geom_label(
aes(label = R),
data = . %>%
dplyr::filter(date == max(date)) %>%
mutate(R = round(R, 2), date = date + 1),
fill = rgb(1, 1, 1, 0.3),
show.legend = FALSE
) +
labs(
x = "Date", y = "Growth Factor"
) +
facet_wrap(~`Province/State`, scales = "free_x") +
theme(legend.position = "none") +
coord_cartesian(ylim = c(0.0, 3))
gf
Growth factor for each State/Territory. This value becomes volatile when daily new cases approach zero as is commonly observed in small populations, and at the end stages of an outbreak. In order to try and minimise volatility a 14 day simple moving average was used, in contrast to the 5 day average as advocated here. This enables assessment of the growth factor over an entire quarantine period. If no new cases are observed over this period, the value is not able to be calculated. The dashed vertical lines indicate the day most state borders were closed.
The current 14 day growth factor is 1.1 which gives considerable cause for concern. In particular, the outbreak in Victoria is clearly not under control.
latestAU %>%
dplyr::select(State, Tested = tested) %>%
write_tsv(
glue(
"tested/tested_{format(dt, '%Y%m%d')}.tsv"
)
)
Testing numbers were initially sourced from manual inspection of individual press releases for NSW, QLD, VIC, WA, SA, TAS, ACT and the NT. Updates on testing numbers beyond the initial values were performed automatically using the above code which probes each state’s official releases for the latest values, and updates where found. The number of tested individuals in each state was then assessed as a function of State population size. All results are valid at the time of report generation.
latestAU %>%
dplyr::select(State, Tested = tested) %>%
full_join(
confirmed %>%
dplyr::filter(
date == max(date),
Country == "Australia"
) %>%
rename(
State = `Province/State`
)
) %>%
mutate(
Tested = case_when(
is.na(Tested) ~ confirmed,
Tested < confirmed ~ confirmed,
!is.na(Tested) ~ Tested
)
) %>%
left_join(ausPops) %>%
bind_rows(
tibble(
State = "Total",
Population = sum(.$Population, na.rm = TRUE),
confirmed = sum(.$confirmed, na.rm = TRUE),
Tested = sum(.$Tested, na.rm = TRUE)
)
) %>%
mutate(
`Tests / '000` = round(1e3 * Tested / Population, 2),
Positive = confirmed / Tested,
Negative = 1 - Positive,
isTotal = grepl("Total", State)
) %>%
dplyr::select(
State, Population,
Confirmed = confirmed,
Tested,
contains("000"),
ends_with("ive"),
isTotal
) %>%
arrange(isTotal, desc(`Tests / '000`)) %>%
dplyr::select(-isTotal) %>%
dplyr::rename(
`% Positive Tests` = Positive,
`% Negative Tests` = Negative
) %>%
mutate_at(
vars(starts_with("%")), percent, accuracy = 0.01
) %>%
pander(
justify = "lrrrrrr",
missing = "",
caption = glue(
"*COVID-19 testing scaled by state population size.
Confirmed cases are assumed to be the tests returning a positive result.
The current numbers available for some states are a lower limit, and as such, the proportion of the population tested is likely to be higher, as is the proportion of tests returning a negative result.*"
),
emphasize.strong.rows = nrow(.)
)
| State | Population | Confirmed | Tested | Tests / ’000 | % Positive Tests | % Negative Tests |
|---|---|---|---|---|---|---|
| Victoria | 6,629,870 | 2,303 | 850,000 | 128.2 | 0.27% | 99.73% |
| New South Wales | 8,117,976 | 3,211 | 889,914 | 109.6 | 0.36% | 99.64% |
| Tasmania | 535,500 | 228 | 50,606 | 94.5 | 0.45% | 99.55% |
| South Australia | 1,756,494 | 443 | 155,483 | 88.52 | 0.28% | 99.72% |
| Queensland | 5,115,451 | 1,067 | 376,719 | 73.64 | 0.28% | 99.72% |
| Australian Capital Territory | 428,060 | 108 | 31,197 | 72.88 | 0.35% | 99.65% |
| Western Australia | 2,630,557 | 611 | 188,953 | 71.83 | 0.32% | 99.68% |
| Northern Territory | 245,562 | 31 | 13,604 | 55.4 | 0.23% | 99.77% |
| Total | 25,459,470 | 8,002 | 2,556,476 | 100.4 | 0.31% | 99.69% |
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
locale: LC_CTYPE=C, LC_NUMERIC=C, LC_TIME=C, LC_COLLATE=C, LC_MONETARY=C, LC_MESSAGES=en_AU.UTF-8, LC_PAPER=en_AU.UTF-8, LC_NAME=C, LC_ADDRESS=C, LC_TELEPHONE=C, LC_MEASUREMENT=en_AU.UTF-8 and LC_IDENTIFICATION=C
attached base packages: stats, graphics, grDevices, utils, datasets, methods and base
other attached packages: readxl(v.1.3.1), ggfortify(v.0.4.10), QuantTools(v.0.5.7), data.table(v.1.12.8), cowplot(v.1.0.0), plotly(v.4.9.2.1), DT(v.0.14), pander(v.0.6.3), RCurl(v.1.98-1.2), rvest(v.0.3.5), xml2(v.1.3.2), jsonlite(v.1.7.0), glue(v.1.4.1), broom(v.0.5.6), ggrepel(v.0.8.2), matrixStats(v.0.56.0), scales(v.1.1.1), lubridate(v.1.7.9), magrittr(v.1.5), forcats(v.0.5.0), stringr(v.1.4.0), dplyr(v.1.0.0), purrr(v.0.3.4), readr(v.1.3.1), tidyr(v.1.1.0), tibble(v.3.0.1), ggplot2(v.3.3.2) and tidyverse(v.1.3.0)
loaded via a namespace (and not attached): httr(v.1.4.1), viridisLite(v.0.3.0), here(v.0.1), modelr(v.0.1.8), fasttime(v.1.0-2), assertthat(v.0.2.1), highr(v.0.8), selectr(v.0.4-2), blob(v.1.2.1), cellranger(v.1.1.0), yaml(v.2.2.1), pillar(v.1.4.4), backports(v.1.1.8), lattice(v.0.20-41), digest(v.0.6.25), colorspace(v.1.4-1), htmltools(v.0.5.0), pkgconfig(v.2.0.3), haven(v.2.3.1), generics(v.0.0.2), farver(v.2.0.3), ellipsis(v.0.3.1), withr(v.2.2.0), lazyeval(v.0.2.2), cli(v.2.0.2), crayon(v.1.3.4), evaluate(v.0.14), fs(v.1.4.1), fansi(v.0.4.1), nlme(v.3.1-148), Cairo(v.1.5-12), tools(v.3.6.3), hms(v.0.5.3), lifecycle(v.0.2.0), munsell(v.0.5.0), reprex(v.0.3.0), compiler(v.3.6.3), rlang(v.0.4.6), grid(v.3.6.3), rstudioapi(v.0.11), htmlwidgets(v.1.5.1), crosstalk(v.1.1.0.1), labeling(v.0.3), bitops(v.1.0-6), rmarkdown(v.2.3), gtable(v.0.3.0), DBI(v.1.1.0), curl(v.4.3), R6(v.2.4.1), gridExtra(v.2.3), knitr(v.1.29), rprojroot(v.1.3-2), stringi(v.1.4.6), Rcpp(v.1.0.4.6), vctrs(v.0.3.1), dbplyr(v.1.4.4), tidyselect(v.1.1.0) and xfun(v.0.15)